package com.hex.ds.hdrs.period.task.controller;


import com.hex.bigdata.hbda.annotation.Log;
import com.hex.bigdata.hbda.base.Page;
import com.hex.ds.hdrs.period.task.dto.MutexPoolDto;
import com.hex.ds.hdrs.period.task.po.MutexPool;
import com.hex.ds.hdrs.period.task.service.MutexPoolService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 互斥池管理表 前端控制器
 * </p>
 *
 * @author tangji
 * @since 2021-01-21
 */

@Slf4j
@RestController
@Api(tags = "互斥池管理")
@RequestMapping("/api/mutexPool")
@RequiredArgsConstructor(onConstructor_ = {@Lazy, @Autowired})
public class MutexPoolController {

    private final MutexPoolService mutexPoolService;

    /*
     * @Method: queryListByPage <br>
     * @Param: [mutexPool, page] <br>
     * @Return: org.springframework.http.ResponseEntity<java.lang.Object> <br>
     * @Description：<br>
     * @Author： wz.li<br>
     * @Date： 2023/7/5 14:48 <br>
     * @Version： V2.0.2<br>
     */
    @GetMapping
    @ApiOperation("分页查询互斥池配置")
    public ResponseEntity<Object> queryListByPage(MutexPool mutexPool, Page page) {
        log.debug("进入【MutexPoolController.queryListByPage】,参数: {}", mutexPool.toString());
        return new ResponseEntity(mutexPoolService.queryListByPage(mutexPool, page), HttpStatus.OK);
    }

    /*
     * @Method: addAppMutexPool <br>
     * @Param: [mutexPoolDto] <br>
     * @Return: org.springframework.http.ResponseEntity<java.lang.Object> <br>
     * @Description：应用管理员新增互斥任务<br>
     * @Author： wz.li<br>
     * @Date： 2023/7/5 9:49 <br>
     * @Version： V2.0.2<br>
     */
    @Log("互斥池新增任务")
    @PostMapping("/addAppMutexPool")
    @ApiOperation("添加应用互斥池配置")
    public ResponseEntity<Object> addAppMutexPool(@RequestBody MutexPoolDto mutexPoolDto) {
        log.info("进入【MutexPoolController.addAppMutexPool】,参数: {}", mutexPoolDto.toString());
        mutexPoolService.addAppMutexPool(mutexPoolDto);
        return new ResponseEntity<>("新增成功！", HttpStatus.OK);
    }

    /*
     * @Method: appDelMutexPool <br>
     * @Param: [mutexPoolDto] <br>
     * @Return: org.springframework.http.ResponseEntity<java.lang.Object> <br>
     * @Description：应用管理员删除互斥任务<br>
     * @Author： wz.li<br>
     * @Date： 2023/7/5 14:13 <br>
     * @Version： V2.0.2<br>
     */
    @PostMapping("/appDelMutexPool")
    @ApiOperation("互斥池删除任务")
    @Log("互斥池删除任务")
    public ResponseEntity<Object> appDelMutexPool(@RequestBody MutexPoolDto mutexPoolDto) {
        log.info("进入【MutexPoolController.appDelMutexPool】,参数: {}", mutexPoolDto.toString());
        mutexPoolService.appDelMutexPool(mutexPoolDto);
        return new ResponseEntity<>("新增成功！", HttpStatus.OK);
    }

    /*
     * @Method: addAdminMutexPool <br>
     * @Param: [mutexPoolDto] <br>
     * @Return: org.springframework.http.ResponseEntity<java.lang.Object> <br>
     * @Description：系统管理员新增互斥任务<br>
     * @Author： wz.li<br>
     * @Date： 2023/7/5 13:55 <br>
     * @Version： V2.0.2<br>
     */
    @PutMapping("/addAdminMutexPool")
    @ApiOperation("添加系统互斥池配置")
    public ResponseEntity<Object> addAdminMutexPool(@RequestBody MutexPoolDto mutexPoolDto) {
        log.info("进入了MutexPoolController的addAppMutexPool方法");
        mutexPoolService.addAdminMutexPool(mutexPoolDto);
        return new ResponseEntity<>("新增成功！", HttpStatus.OK);
    }

    /*
     * @Method: delAdminMutexPool <br>
     * @Param: [mutexPoolDto] <br>
     * @Return: org.springframework.http.ResponseEntity<java.lang.Object> <br>
     * @Description：系统管理员删除互斥任务<br>
     * @Author： wz.li<br>
     * @Date： 2023/7/5 13:57 <br>
     * @Version： V2.0.2<br>
     */
    @PostMapping("/delAdminMutexPool")
    @ApiOperation("删除系统互斥池配置")
    public ResponseEntity<Object> delAdminMutexPool(@RequestBody MutexPoolDto mutexPoolDto) {
        log.info("进入了MutexPoolController.delAdminMutexPool方法");
        mutexPoolService.delAdminMutexPool(mutexPoolDto);
        return new ResponseEntity<>("新增成功！", HttpStatus.OK);
    }
}

